//
//  WmcCommonButton.swift
//  YPWatermarkCamera
//
//  Created by yupao_ios_macmini06 on 2022/9/13.
//

import UIKit

/// 普通按钮，可能不需要图片
class WmcNormalButton: WmcImgTextControl {
    override func config() {
        label.textAlignment = .center
    }

    /// 进行布局
    override func layoutImgText() {
        if let _ = imageView.image {
            // 有图片
            if label.text == "" || label.text == nil {
                imageView.snp.remakeConstraints { make in
                    make.top.equalTo(contentEdge.top)
                    make.left.equalTo(contentEdge.left)
                    make.bottom.equalTo(-contentEdge.bottom)
                    if let imgSize = imgSize {
                        make.width.equalTo(imgSize)
                    } else {
                        make.right.equalTo(-contentEdge.right)
                    }
                }
            } else {
                imageView.snp.remakeConstraints { make in
                    make.top.equalTo(contentEdge.top)
                    make.left.equalTo(contentEdge.left)
                    make.bottom.equalTo(-contentEdge.bottom)
                    if let imgSize = imgSize {
                        make.width.equalTo(imgSize)
                    } else {
                        make.right.equalTo(label.snp.left).offset(-imgTextSpacing)
                    }
                }

                label.snp.remakeConstraints { make in
                    make.top.equalTo(contentEdge.top)
                    make.right.equalTo(-contentEdge.right)
                    make.bottom.equalTo(-contentEdge.bottom)
                    if let _ = imgSize {
                        make.left.equalTo(imageView.snp.right).offset(imgTextSpacing)
                    }
                }
            }
            label.adjustsFontSizeToFitWidth = true
            imageView.isHidden = false
        } else {
            // 没图片
            label.snp.remakeConstraints { make in
                make.top.equalTo(contentEdge.top)
                make.right.equalTo(-contentEdge.right)
                make.bottom.equalTo(-contentEdge.bottom)
                make.left.equalTo(contentEdge.left)
            }
            label.adjustsFontSizeToFitWidth = true
            imageView.isHidden = true
        }
    }
}
